package com.sunwayworld.basemodule.business.qualitycontrol.qualityrule.service.impl;

import com.sunwayworld.basemodule.business.qualitycontrol.qualityrule.bean.LimsQualityRuleBean;
import com.sunwayworld.basemodule.business.qualitycontrol.qualityrule.dao.LimsQualityRuleDao;
import com.sunwayworld.basemodule.business.qualitycontrol.qualityrule.service.LimsQualityRuleService;
import com.sunwayworld.framework.at.annotation.AuditTrailEntry;
import com.sunwayworld.framework.at.annotation.AuditTrailType;
import com.sunwayworld.framework.context.ApplicationContextHelper;
import com.sunwayworld.framework.restful.data.RestJsonWrapperBean;
import com.sunwayworld.framework.spring.annotation.GikamBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
@GikamBean
public class LimsQualityRuleServiceImpl implements LimsQualityRuleService {

    @Autowired
    private LimsQualityRuleDao limsQualityRuleDao;

    @Override
    @SuppressWarnings("unchecked")
    public LimsQualityRuleDao getDao() {
        return limsQualityRuleDao;
    }

    @Override
    @Transactional
    @AuditTrailEntry(AuditTrailType.INSERT)
    public Long insert(RestJsonWrapperBean jsonWrapper) {
        LimsQualityRuleBean limsQualityRule = jsonWrapper.parseUnique(LimsQualityRuleBean.class);
        limsQualityRule.setId(ApplicationContextHelper.getNextIdentity());
        getDao().insert(limsQualityRule);
        return limsQualityRule.getId();
    }

}
